package model;

import java.text.DateFormat;
import java.util.ArrayList;

public class OrderContainer {

	private ArrayList<Order> orderList;
	private static OrderContainer orderContainer = null;
	
	private OrderContainer(){
		orderList = new ArrayList<Order>();
		orderDatabase();
	}
	
	public static OrderContainer getInstance(){
		if(orderContainer == null){
			orderContainer = new OrderContainer();
		}
		return orderContainer;
	}

	public boolean addOrder(Order order) {
		return orderList.add(order);
	}

	public boolean removeOrder(Order order) {
		return orderList.remove(order);
	}
	
	public Order findOrder(int id){
		for(Order order : orderList){
			if(order.getId() == id){
				return order;
			}
		}
		return null;
	}
	
	//** Returns an ArrayList of Order objects by Order ID */
	public ArrayList<String> getOrders(int id){
		ArrayList<String> al = new ArrayList<String>();
		for(Order order : orderList){
			if(order.getCustomerId() == id){
				al.add(String.valueOf(order.getId()));// string skal laves til int ved lejlighed.
			}
		}	
		return al;
	}
	
	private void orderDatabase(){
		orderList.add(new Order(1001, DateFormat.getDateTimeInstance(), true, "Status: ikke leveret", 98444444));
		orderList.add(new Order(1002, DateFormat.getDateTimeInstance(), true, "Status: leveret", 98444444));
		orderList.add(new Order(1003, DateFormat.getDateTimeInstance(), true, "Status: leveret", 98222222));
		orderList.add(new Order(1004, DateFormat.getDateTimeInstance(), false, "Status: ikke leveret", 98111111));
		orderList.add(new Order(1005, DateFormat.getDateTimeInstance(), true, "Status: leveret", 98333333));
	}
}
